<template>
  <div class="login-container">
    <div class="logo" />
    <div class="form">
      <h1>智慧园区-登录</h1>
      <el-card shadow="never" class="login-card">
        <!--登录表单-->
        <el-form ref="loginRef" :model="loginForm" :rules="loginRules">
          <el-form-item prop="username">
            账号
            <el-input v-model="loginForm.username" placeholder="请输入用户名" />
          </el-form-item>
          <el-form-item prop="password">
            密码
            <el-input v-model="loginForm.password" show-password placeholder="请输入密码" />
          </el-form-item>
          <el-form-item>
            <el-checkbox v-model="loginForm.isAgree">记住我</el-checkbox>
          </el-form-item>
          <el-form-item>
            <el-button style="width:350px" type="primary" @click="loginUser"> 登录</el-button>
          </el-form-item>
        </el-form>
      </el-card>

    </div>

  </div>

</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        username: 'demo',
        password: 'Hmzs%001',
        isAgree: false
      },
      loginRules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    async loginUser() {
      await this.$refs.loginRef.validate()
      await this.$store.dispatch('user/login', { username: this.loginForm.username, password: this.loginForm.password })
      this.$router.push('/')
    }
  }
}
</script>

<style lang="scss">
.login-container {
  display: flex;
  align-items: stretch;
  height: 96vh;

  .logo {
    flex: 3;
    background: rgba(38, 72, 176) url(../../assets/common/login-bg.svg) no-repeat center / cover;
  }

  .form {
    flex: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-left: 176px;

    .el-card {
      border: none;
      padding: 0;
    }

    h1 {
      padding-left: 20px;
      font-size: 24px;
    }

    ::v-deep .el-input {
      width: 350px;
      height: 44px;

      .el-input__inner {
        background: #f4f5fb;
      }
    }

    ::v-deep .el-checkbox {
      color: #606266;
    }
  }
}
</style>
